<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends LW_Controller {

	protected $assets;
	public function __construct()
	{
		parent::__construct();
		// 初始化样式
		$this->assets = $this->lw_assets->getAssets(array('revolution_slider'));
		$this->load->library('lw_db',array('tb_name'=>'tb_film_list'),'tb_film_list');
		$this->load->model('film_model');
//		$this->output->cache(60);
	}

	public function index()
	{
		$data = $this->data; // 继承的数据
		$this->assets['pageCss'] = array(base_url('assets/pages/home/css/index.css'));
		$this->assets['pageJs'] = array(base_url('assets/pages/home/script/index.js'));
		$data['assets'] = $this->assets;
		$data['pageTitle'] = '最新电影';
		$data['cateFilmList'] = $this->getNewsFilm(5);
		$this->load->library('lw_emails');
		$this->lw_load->view('home/index',$data);
	}

	public function getNewsFilm($num=5)
	{
		$this->load->library('lw_db',array('tb_name'=>'tb_film_category'),'tb_film_category');
		$rowsCategory = $this->tb_film_category->get_all();
		$cateFilmList = array();
		for($i=0;$i<sizeof($rowsCategory);$i++){
			$cateFilmList[$i] = array();
			$cateFilmList[$i]['cateInfo'] = $rowsCategory[$i];
			$cateFilmList[$i]['newFilmList'] = $data['filmList'] = $this->film_model->get_new_film($rowsCategory[$i]['id'],$num);
		}
		return $cateFilmList;
	}

	public function email()
	{
		$this->load->library('email');
		$config['protocol'] = 'smtp';
		$config['smtp_host'] = 'ssl://smtp.qq.com';
		$config['smtp_user'] = '1023953303@qq.com';
		$config['smtp_pass'] = 'vqdiaesoknwnbedc';//去QQ邮箱设置开启smtp
		$config['smtp_port'] = 465;
		$config['smtp_timeout'] = 30;
		$config['mailtype'] = 'text';
		$config['charset'] = 'utf-8';
		$config['wordwrap'] = TRUE;
		$this->email->initialize($config);
		$this->email->set_newline("\r\n");
		$config['crlf'] = "\r\n";
		$this->email->from('1023953303@qq.com', '云阅书城');
		$this->email->to('1013269528@qq.com');

		$this->email->subject('刘小白占小胖工作室【官方邮箱】');
		$this->email->message('这是一个正式的邀请函：邀请占小胖前往工作室工作。');
		// 附件
		$this->email->attach('http://love.doghouse.com.tw/image/wallpaper/011102/bf1554.jpg');
		$this->email->send();
		return $this->email->print_debugger();
	}
}
